﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace NexTrackDesktop.ViewModels
{
    /// <summary>
    /// This class links the playlist to the playlist view
    /// </summary>
    class PlaylistViewModel : ViewModelBase
    {
        public ObservableCollection<SongViewModel> Songs { get; set; }

        public PlaylistViewModel()
        {
            Songs = new ObservableCollection<SongViewModel>();
            Client.PartyLoaded += new Action(Client_PartyStarting);
        }

        void  Client_PartyStarting()
        {
            Client.Party.Playlist.PlaylistChanged += new Action(Playlist_PlaylistChanged);
        }

        /// <summary>
        /// This method links the action of a playlist changed to playlist view
        /// </summary>
        void Playlist_PlaylistChanged()
        {
            var playlist = Client.Party.Playlist.Items;

            Songs.UpdateInPlace(playlist, (svm, s) => { if(svm.Song != s) svm.Song = s; });
        }

    }
}
